package com.ruoyi.project.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.A05Project;
import com.ruoyi.project.domain.A08PaymentReceipt;
import com.ruoyi.project.service.IA05ProjectService;
import com.ruoyi.project.vo.A05Project.A05DownListZupRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 项目库Controller
 *
 * @author WorrilessGo
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/project")
public class A05ProjectController extends BaseController
{
    @Autowired
    private IA05ProjectService a05ProjectService;

    /**
     * 查询项目库列表
     */
    @GetMapping("/list")
    @RequiresPermissions("project:project:list")
    public TableDataInfo list(A05Project a05Project)
    {
        startPage();
        List<A05Project> list = a05ProjectService.selectA05ProjectList(a05Project);
        return getDataTable(list);
    }



    /**
     * 查询项目库列表
     */
    @GetMapping("/code")
    @RequiresPermissions("project:project:code")
    public AjaxResult code(A05Project a05Project)
    {
        List<String> list = a05ProjectService.selectA05ProjectCode(a05Project);
        AjaxResult success = success(list);
        return success;
    }

    /**
     * 导出项目库列表
     */
    @Log(title = "项目库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @RequiresPermissions("project:project:export")
    public void export(HttpServletResponse response, A05Project a05Project)
    {
        List<A05Project> list = a05ProjectService.selectA05ProjectList(a05Project);
        ExcelUtil<A05Project> util = new ExcelUtil<A05Project>(A05Project.class);
        util.exportExcel(response, list, "项目库数据");
    }
    @RequiresPermissions("project:receipt:export")
    @PostMapping("/exportModel")
    public void exportModel(HttpServletResponse response)
    {
        A05Project a05Project = new A05Project();
        List<A05Project> list = Arrays.asList(a05Project);
        ExcelUtil<A05Project> util = new ExcelUtil<A05Project>(A05Project.class);
        util.exportExcel(response, list, "项目库数据");
    }

    /**
     * 批量下载项目文件
     * @param a05DownListZupRequest
     */
    @RequiresPermissions("project:receipt:export")
    @PostMapping(value = "/determineType")
    public void determineType(A05DownListZupRequest a05DownListZupRequest, HttpServletResponse response)
    {

        a05ProjectService.downloadProjectFiles(a05DownListZupRequest.getProjectIds(),response);
    }


    /**
     * 汇总
     * @param
     */
    @PostMapping("/summary")
    @RequiresPermissions("project:receipt:export")
    public AjaxResult summary(@RequestBody A08PaymentReceipt a08PaymentReceipt)
    {
        String message = a05ProjectService.summary(a08PaymentReceipt);
        return success(message);
    }



    /**
     * 导入项目库数据
     */
    @Log(title = "项目库", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @RequiresPermissions("project:receipt:export")
    public AjaxResult importData(MultipartFile file) throws Exception{
        ExcelUtil<A05Project> util = new ExcelUtil<A05Project>(A05Project.class);
        List<A05Project> list = util.importExcel(file.getInputStream());
        int message = a05ProjectService.batchInsertA05Project(list);
        return toAjax(message);

    }

    /**
     * 获取项目库详细信息
     */
    @GetMapping(value = "/{projectId}")
    @RequiresPermissions("project:project:query")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId)
    {
        return success(a05ProjectService.selectA05ProjectByProjectId(projectId));
    }

    /**
     * 新增项目库
     */
    @Log(title = "项目库", businessType = BusinessType.INSERT)
    @PostMapping
    @RequiresPermissions("project:project:add")
    public AjaxResult add(@RequestBody A05Project a05Project)
    {
        return toAjax(a05ProjectService.insertA05Project(a05Project));
    }

    /**
     * 修改项目库
     */
    @Log(title = "项目库", businessType = BusinessType.UPDATE)
    @PutMapping
    @RequiresPermissions("project:project:edit")
    public AjaxResult edit(@RequestBody A05Project a05Project)
    {
        return toAjax(a05ProjectService.updateA05Project(a05Project));
    }


    /**
     * 删除项目库
     */
    @Log(title = "项目库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    @RequiresPermissions("project:project:remove")
    public AjaxResult remove(@PathVariable String[] projectIds)
    {
        return toAjax(a05ProjectService.deleteA05ProjectByProjectIds(projectIds));
    }



}
